<?php
// +----------------------------------------------------------------------
// | 后台首页入口
// +----------------------------------------------------------------------
namespace app\admin\controller\soft;
use app\admin\Adminbase;
use think\Controller;
use think\facade\View;
use think\Request;

class index extends Adminbase
{
	
	/** 
	* @func_code  
	* @action_code 
	* 后台入口
	* /modules/index/index
	*/
    public function index(Request $request){
        $url = $request->path();
        $url = urldecode(count(explode('/',$url)) > 1 ? $url : "modules/index/index");
        $this->assign('navTpl', model('nav','service')->getNavTpl($request->userInfo,$url) );
		if($request->userInfo['shop_id'] > 0){
			$name = model('shop')->where('id',$request->userInfo['shop_id'] )->value('name');
			$request->userInfo['user_name'] = $name;
		}
        $this->assign('userInfo', $request->userInfo );
        $this->assign('userAction',  json_encode(request()->userAction));
        return $this->fetch( $this->url_transform($url) );
    }
    
    
	/**
     * 路由转换
     * @return boolean
     */
	private function url_transform($url){
	 	if( strstr( strtolower($url),"__public__") || strstr( strtolower($url),"public") ){
            if(INDEX_PATH == '/'){
                View::config('view_path','./public/');
            }else{
                View::config('view_path','../public/');
            }
			$url = str_replace("__public__/","",$url);
			$url = str_replace("__PUBLIC__/","",$url);
		}
		if( strstr( strtolower($url),"__root__") || strstr( strtolower($url),"root") ){
            if(INDEX_PATH == '/'){
                View::config('view_path','./');
            }else{
                View::config('view_path','../');
            }
			$url = str_replace("__root__/","",$url);
			$url = str_replace("__ROOT__/","",$url);
		}
		return $url;
	}
	
}
